From 6b7c2a8144ce060a6cb01eb06eb0e5dd20729b29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jes=C3=BAs=20Espino?= Date: Tue, 8 Mar 2016 09:27:09 +0100 Subject: [PATCH] Allow multiple search query params --- src/bin/search.rs | 6 ++--- tests/test_cargo_search.rs | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/bin/search.rs b/src/bin/search.rs index 8b8c010e6..2eae9173c 100644 --- a/src/bin/search.rs +++ b/src/bin/search.rs @@ -10,14 +10,14 @@ pub struct Options { flag_quiet: Option, flag_color: Option, flag_limit: Option, - arg_query: String + arg_query: Vec } pub const USAGE: &'static str = " Search packages in crates.io Usage: - cargo search [options] + cargo search [options] ... cargo search [-h | --help] Options: @@ -40,6 +40,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { .. } = options; - try!(ops::search(&query, config, host, cmp::min(100, limit.unwrap_or(10)) as u8)); + try!(ops::search(&query.join("+"), config, host, cmp::min(100, limit.unwrap_or(10)) as u8)); Ok(None) } diff --git a/tests/test_cargo_search.rs b/tests/test_cargo_search.rs index d4c483872..24fa9a5e1 100644 --- a/tests/test_cargo_search.rs +++ b/tests/test_cargo_search.rs @@ -86,6 +86,52 @@ test!(simple { hoare (0.1.1) Design by contract style assertions for Rust", updating = UPDATING))); }); +test!(multiple_query_params { + let contents = r#"{ + "crates": [{ + "created_at": "2014-11-16T20:17:35Z", + "description": "Design by contract style assertions for Rust", + "documentation": null, + "downloads": 2, + "homepage": null, + "id": "hoare", + "keywords": [], + "license": null, + "links": { + "owners": "/api/v1/crates/hoare/owners", + "reverse_dependencies": "/api/v1/crates/hoare/reverse_dependencies", + "version_downloads": "/api/v1/crates/hoare/downloads", + "versions": "/api/v1/crates/hoare/versions" + }, + "max_version": "0.1.1", + "name": "hoare", + "repository": "https://github.com/nick29581/libhoare", + "updated_at": "2014-11-20T21:49:21Z", + "versions": null + }], + "meta": { + "total": 1 + } + }"#; + let base = api_path().join("api/v1/crates"); + + // Older versions of curl don't peel off query parameters when looking for + // filenames, so just make both files. + // + // On windows, though, `?` is an invalid character, but we always build curl + // from source there anyway! + File::create(&base).unwrap().write_all(contents.as_bytes()).unwrap(); + if !cfg!(windows) { + File::create(&base.with_file_name("crates?q=postgres+sql&per_page=10")).unwrap() + .write_all(contents.as_bytes()).unwrap(); + } + + assert_that(cargo_process("search").arg("postgres").arg("sql"), + execs().with_status(0).with_stdout(format!("\ +{updating} registry `[..]` +hoare (0.1.1) Design by contract style assertions for Rust", updating = UPDATING))); +}); + test!(help { assert_that(cargo_process("search").arg("-h"), execs().with_status(0)); -- 2.30.2